package com.zhaoyizhe.demo.controller;

import com.zhaoyizhe.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/response")
public class ResponseController {
    @RequestMapping("/response")
    public String response(){
        return "/Test.html";
    }

    @ResponseBody
    @RequestMapping("/returnHtml")
    public String returnHtml(){
        return "<h1>hehe<h1>";
    }

    @ResponseBody
    @RequestMapping("/returnJson")
    public UserInfo returnJson(){
        UserInfo userInfo = new UserInfo("zhangSan",18,"123456");
        return userInfo;
    }

    @ResponseBody
    @RequestMapping("/setStatus")
    public String setStatus(HttpServletResponse response){
        response.setStatus(401);
        return "状态码设置成功";
    }

    @ResponseBody
    @RequestMapping("/setHeader")
    public String setHeader(HttpServletResponse response){
        response.setHeader("aaa","bbbb");
        return "设置Header成功";

    }

}
